package com.xbongbong.pay.platform.wechatpay.enums;

import lombok.Getter;

import java.util.Objects;

/**
 * 退款错误码
 * @author 魏荣杰
 * @date 2021/1/12 10:11
 * @since
 * @version
 */
@Getter
public enum WeChatApplyRefundErrorEnum {
    /**
     *
     */
    SUCCESS("SUCCESS", "成功"),
    SYSTEMERROR("SYSTEMERROR", "接口返回错误"),
    BIZERR_NEED_RETRY("BIZERR_NEED_RETRY", "退款业务流程错误，需要商户触发重试来解决"),
    TRADE_OVERDUE("TRADE_OVERDUE", "订单已经超过退款期限"),
    ERROR("ERROR", "业务错误"),
    USER_ACCOUNT_ABNORMAL("USER_ACCOUNT_ABNORMAL", "退款请求失败"),
    INVALID_REQ_TOO_MUCH("INVALID_REQ_TOO_MUCH", "无效请求过多"),
    NOTENOUGH("NOTENOUGH", "余额不足"),
    INVALID_TRANSACTIONID("INVALID_TRANSACTIONID", "无效transaction_id"),
    PARAM_ERROR("PARAM_ERROR", "参数错误"),
    APPID_NOT_EXIST("APPID_NOT_EXIST", "APPID不存在"),
    MCHID_NOT_EXIST("MCHID_NOT_EXIST", "MCHID不存在"),
    ORDERNOTEXIST("ORDERNOTEXIST", "订单号不存在"),
    REQUIRE_POST_METHOD("REQUIRE_POST_METHOD", "请使用post方法"),
    SIGNERROR("SIGNERROR", "签名错误"),
    XML_FORMAT_ERROR("XML_FORMAT_ERROR", "XML格式错误"),
    FREQUENCY_LIMITED("FREQUENCY_LIMITED", "频率限制"),
    NOAUTH("NOAUTH", "异常IP请求不予受理"),
    CERT_ERROR("CERT_ERROR", "证书校验错误"),
    REFUND_FEE_MISMATCH("REFUND_FEE_MISMATCH", "订单金额或退款金额与之前请求不一致，请核实后再试"),
    INVALID_REQUEST("INVALID_REQUEST", "请求参数符合参数格式，但不符合业务规则"),
    ORDER_NOT_READY("ORDER_NOT_READY", "订单处理中，暂时无法退款，请稍后再试")
    ;

    /**
     * 错误码
     */
    private final String errorCode;
    /**
     * 说明
     */
    private final String msg;

    WeChatApplyRefundErrorEnum(String errorCode, String msg) {
        this.errorCode = errorCode;
        this.msg = msg;
    }

    public static WeChatApplyRefundErrorEnum getByCode(String errorCode) {
        if (Objects.isNull(errorCode) || errorCode.isEmpty()) {
            return null;
        }
        for (WeChatApplyRefundErrorEnum value : values()) {
            if (Objects.equals(value.getErrorCode(), errorCode)) {
                return value;
            }
        }

        return null;
    }
}
